<?php if($action=="index") {?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta name="keywords" content="系统用户组列表">
  <meta name="description" content="系统用户组列表">
  <title>积分订单管理</title>
   <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/css/common.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/js/themes/bootstrap/easyui.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/js/themes/icon.css" />
 
  <script type="text/javascript" src="<?php echo site_url(); ?>app/views/js/jquery.min.js"></script>
  <script type="text/javascript" src="<?php echo site_url(); ?>app/views/js/jquery.easyui.min.js"></script>
 <script type="text/javascript" src="<?php echo site_url(); ?>app/views/js/locale/easyui-lang-zh_CN.js"></script>

  <script type="text/javascript">
    var url;
    function newUser(){
     window.location.href="add";
    }
    function editUser(){
      var row = $('#dg').datagrid('getSelected');
      
      if (row){
         window.location.href='edit/?id='+row.id;
      }else{
         $.messager.alert('提示','请选择要编辑的行！');
      }
    }
    
    function removeUser(){
      var row = $('#dg').datagrid('getSelected');
      if (row){
        $.messager.confirm('确认提示','你确定要删除这个订单？',function(r){
          if (r){
            $.post('del',{id:row.id},function(result){
              if (result.success){
                $('#dg').datagrid('reload');  // reload the user data
              } else {
                $.messager.show({ // show error message
                  title: 'Error',
                  msg: result.msg
                });
              }
            },'json');
          }
        });
      }else{
        $.messager.alert("提示","请选中要删除的行！");
      }
    }
  </script>
</head>
<body>
  <h2 class="navfont">积分录入订单管理:</h2>
  

  <table id="dg" title="" class="easyui-datagrid" style="width:1200px;height:550px"
      url="get_order"
      toolbar="#toolbar" pagination="true"
      rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
      <tr>
        <th field="id" width="50">编号</th>
        <th field="empname" width="50">员工名称</th>
         <th field="emptelphone" width="50">员工电话</th>
          <th field="empdepartname" width="50">员工部门</th>
           <th field="sumtotal" width="50">总积分</th>
          <th field="time">录入时间</th>
      </tr>
    </thead>
  </table>
  <div id="toolbar">
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">新增</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">编辑</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeUser()">删除</a>
  </div>

 
  
</body>
</html>

<?php } elseif($action=="add"){ ?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title></title>

  
  <script type="text/javascript" src="<?php echo site_url(); ?>app/views/assetstwo/easyui/jquery.min.js"></script>
 

  <link href="<?php echo site_url(); ?>app/views/assetstwo/table/footable.core.css?v=2-0-1" rel="stylesheet" type="text/css"/>
    <link href="<?php echo site_url(); ?>app/views/assetstwo/table/footable-demos.css" rel="stylesheet" type="text/css"/>
   
    <script>
        if (!window.jQuery) { document.write('<script src="js/jquery-1.9.1.min.js"><\/script>'); }
    </script>
    <script src="<?php echo site_url(); ?>app/views/assetstwo/table/footable.js?v=2-0-1" type="text/javascript"></script>
    <script src="<?php echo site_url(); ?>app/views/assetstwo/table/footable.sort.js?v=2-0-1" type="text/javascript"></script>
    <script src="<?php echo site_url(); ?>app/views/assetstwo/table/footable.filter.js?v=2-0-1" type="text/javascript"></script>
    <script src="<?php echo site_url(); ?>app/views/assetstwo/table/footable.paginate.js?v=2-0-1" type="text/javascript"></script>
  
    <script src="<?php echo site_url(); ?>app/views/assetstwo/table/demos.js" type="text/javascript"></script>
    <!-- paste this code into your webpage -->
<link href="<?php echo site_url(); ?>app/views/assetstwo/table/tablecloth.css" rel="stylesheet" type="text/css" media="screen" /> 
<script type="text/javascript" src="<?php echo site_url(); ?>app/views/assetstwo/table/tablecloth.js"></script>
<!-- end -->

<link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/assetstwo/easyui/themes/bootstrap/easyui.css">
  <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/assetstwo/easyui/themes/icon.css">
  <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/assetstwo/easyui/demo.css">
   <script type="text/javascript" src="<?php echo site_url(); ?>app/views/assetstwo/easyui/jquery.easyui.min.js"></script>
   <script>
 $(function(){
      $('#cc').layout();
      setHeight();
    });
    
   
    function setHeight(){
      var c = $('#cc');
      var p = c.layout('panel','center'); // get the center panel
      var oldHeight = p.panel('panel').outerHeight();
      p.panel('resize', {height:'500'});
      var newHeight = p.panel('panel').outerHeight();
      c.layout('resize',{
        height: (c.height() + newHeight - oldHeight)
      });
    }


  function emp(){
   
    $('#emp').window('open');
  }


  function pro(){
   
    $('#pro').window('open');
  }


 
</script>
</head>
<body>



<div id="cc" style="width:100%;height:500px;">
    <div data-options="region:'north'" style="height:80px">
    <div style="height:15px;"></div>
     <div class="table">
     <table><tr><td>员工姓名:</td><td><input type="text" size="1" onclick="emp()" id="empname"><input type="hidden" value="" id="empid"></td><td>所属部门:</td><td><span id="empdepart"></span></td><td>联系电话:</td><td><span id="empmobile"></span></td><td>时间:</td><td><input type="text" id="time" value="<?php echo @date("Y-m-d"); ?>" size="1"></td></tr></table> 

</div>
    </div>
    <div data-options="region:'south'" style="height:80px;">
        <div style="height:10px;"></div>
         <div class="row">
              <div class="form-actions " style="width:30%;height:100%;position: relative;left:40%">

                <button type="button" class="button button-primary" onclick="save()">保存单据</button>
                <button type="reset" class="button">重置</button>
              </div>
            </div>

    </div>




  <div id="emp" class="easyui-window" title="选择员工" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:800px;height:400px;padding:5px;top:10px;left:200px;">
 
<div class="" style="width:600px;height: 350px;float:right;border: solid 1px #CCC">
  <div class="" style="width: 100%;height: 35px;border:solid 0px #CCC">
  <div style="width: 19%;height: 29px;border: solid 0px #ccc;float:right;text-align: center"><button style="width: 100%;height: 110%" onclick="empsearch()">搜索</button></div>
    <div style="width: 80%;height: 29px;border: solid 0px #ccc;float:left"><input type="text" style="width: 100%;height: 90%;" id="empsearchvalue"></div>
    
  </div>
   <table id="emp_tt" class="easyui-datagrid" title="员工列表" style=""
            data-options="singleSelect:true,url:'<?php  echo site_url();?>index.php/entering/get_emp',method:'get'">
        <thead>
            <tr>
                <th data-options="field:'id'" width="40">编码</th>
                <th data-options="field:'name'" width="100">员工名称</th>
                <th data-options="field:'address'" width="150">地址</th>
                <th data-options="field:'telphone'" width="100">联系电话</th>
                <th data-options="field:'departname'" width="100">所属部门</th>
                 <th data-options="field:'depart'" width="0"></th>
            </tr>
        </thead>
    </table>
</div>
<div class="" style="width:155px;height: 350px;float:left;border: solid 1px #CCC;overflow: hidden">
  
<ul class="easyui-tree" id="empcategory" data-options="url:'<?php  echo site_url();?>index.php/entering/get_emp_category',method:'get',animate:true"></ul>
</div>
  </div>



   <div id="pro" class="easyui-window" title="选择积分项" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:800px;height:400px;padding:5px;top:10px;left:200px;">
       <div class="" style="width:600px;height: 350px;float:right;border: solid 1px #CCC">
  <div class="" style="width: 100%;height: 35px;border:solid 0px #CCC">
  <div style="width: 19%;height: 29px;border: solid 0px #ccc;float:right;text-align: center"><button style="width: 100%;height: 110%" onclick="prosearch()">搜索</button></div>
    <div style="width: 80%;height: 29px;border: solid 0px #ccc;float:left"><input type="text" id="prosearchvalue" style="width: 100%;height: 90%;"></div>
    
  </div>
   <table id="pro_tt" class="easyui-datagrid" title="积分项列表" style=""
            data-options="singleSelect:true,url:'<?php  echo site_url();?>index.php/entering/get_pro',method:'get'">
        <thead>
            <tr>
                <th data-options="field:'id'" width="40">编码</th>
                <th data-options="field:'name'" width="300">积分项名称</th>
                <th data-options="field:'change_num'" width="150">置换分数</th>
                <th data-options="field:'sale'" width="100">专业非专业</th>
               
            </tr>
        </thead>
    </table>
</div>
<div class="" style="width:155px;height: 350px;float:left;border: solid 1px #CCC;overflow: hidden">
  
<ul class="easyui-tree" id="procategory" data-options="url:'<?php  echo site_url();?>index.php/entering/get_pro_category',method:'get',animate:true"></ul>
</div>
  </div>
    <div data-options="region:'center'" style="padding:10px;height:500px">

<!--数据表格开始-->
    <div class="table">
               <input type="hidden" value="5" id="rownum">
               <input type="hidden" value="" id="rowcount">
        <table class="app" data-filter="#filter" data-page-size="100">
          <thead>
            <tr>
               <th >操作</th>
              <th data-toggle="true">
                编号
              </th>
              <th data-hide="phone">
                积分项目名称
              </th>
              <th data-hide="phone">
                积分项目对应积分
              </th>
              <th data-hide="phone">
                  对应数量
              </th>
              <th data-hide="phone">
                小计
              </th>
              
            </tr>
          </thead>
          <tbody>
            <tr>
                <td><span id="id_1">1</span></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#add" class=" add-row">+</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="row-delete" href="#">-</span></a></td>
              <td><a href="#"><input type="text" size="10" onclick="add(1)" id="proname_1" value=""></a><input type="hidden" value="0" id="proid_1"></td>
              <td><span id="score_1"></span></td>
              <td ><input type="text" size="5" onblur="change(1)" id="num_1"></td>
              <td ><span id="all_1" style="font-size: 18px;font-weight: bold"></span></td>
            </tr>
            <tr>
                <td><span id="id_2">2</span></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#add" class=" add-row">+</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="row-delete" href="#">-</span></a></td>
              <td><a href="#"><input type="text" size="10" onclick="add(2)" id="proname_2" value=""></a><input type="hidden" value="0" id="proid_2"></td>
              <td><span id="score_2"></span></td>
              <td ><input type="text" size="5" onblur="change(2)" id="num_2"></td>
              <td ><span id="all_2" style="font-size: 18px;font-weight: bold"></span></td>
            </tr>
            <tr>
                <td><span id="id_3">3</span></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#add" class=" add-row">+</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="row-delete" href="#">-</span></a></td>
              <td><a href="#"><input type="text" size="10" onclick="add(3)" id="proname_3" value=""></a><input type="hidden" value="0" id="proid_3"></td>
              <td><span id="score_3"></span></td>
              <td ><input type="text" size="5" onblur="change(3)" id="num_3"></td>
              <td ><span id="all_3" style="font-size: 18px;font-weight: bold"></span></td>
            </tr>
            <tr>
                <td><span id="id_4">4</span></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#add" class=" add-row">+</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="row-delete" href="#">-</span></a></td>
              <td><a href="#"><input type="text" size="10" onclick="add(4)" id="proname_4" value=""></a><input type="hidden" value="0" id="proid_4"></td>
              <td><span id="score_4"></span></td>
              <td ><input type="text" size="5" onblur="change(4)" id="num_4"></td>
              <td ><span id="all_4" style="font-size: 18px;font-weight: bold"></span></td>
            </tr>
            <tr>
                <td><span id="id_5">5</span></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#add" class=" add-row">+</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="row-delete" href="#">-</span></a></td>
              <td><a href="#"><input type="text" size="10" onclick="add(5)" id="proname_5" value=""></a><input type="hidden" value="0" id="proid_5"></td>
              <td><span id="score_5"></span></td>
              <td ><input type="text" size="5" onblur="change(5)" id="num_5"></td>
              <td ><span id="all_5" style="font-size: 18px;font-weight: bold"></span></td>
            </tr>
          </tbody>
                    <tfoot >
                    <tr>
                        <td colspan="4"></td><td><h2>总计:</h2></td><td><span id="total" style="font-size: 25px;font-weight: bold">0</span></td>
                    </tr>
                    </tfoot>
        </table>


        </div>
       
<!--数据表格结束-->

<input type="hidden" value="<?php echo site_url(); ?>" id="site_url">

  </div>



 <script type="text/javascript">


$('#empcategory').tree({
  onClick:function(row){
  var row = $('#empcategory').tree('getSelected');
  var id=row.id;
   var site_url=$("#site_url").val();
  var url=site_url+"index.php/entering/get_emp/?id="+id;
    $('#emp_tt').datagrid('options').url=url;  
  $('#emp_tt').datagrid('reload');
}});

$('#procategory').tree({
  onClick:function(row){
  var row = $('#procategory').tree('getSelected');
  var id=row.id;
     var site_url=$("#site_url").val();
  var url=site_url+"index.php/entering/get_pro/?id="+id;
    $('#pro_tt').datagrid('options').url=url;  
  $('#pro_tt').datagrid('reload');
}});

$('#emp_tt').datagrid({
 onClickRow:function(row){
    var row=$("#emp_tt").datagrid('getSelected');
    var id=row.id;
    var name=row.name;
    //var code=row.code;
    var departname=row.departname;
    /* var address=row.address;*/
     var telphone=row.telphone;
     $("#empid").val(id);
     $("#empname").val(name);
     $("#empmobile").html(telphone);
    /* $("#empaddress").html(address);*/
     $("#empdepart").html(departname);
      $('#emp').window('close');
 }});


$('#pro_tt').datagrid({
 onClickRow:function(row){
    var row=$("#pro_tt").datagrid('getSelected');
    var id=row.id;
    var name=row.name;
    var score=row.change_num;
   var num=$("#rowcount").val();
   var namestr="#proname_"+num;
   $(namestr).val(name);
      var idstr="#proid_"+num;
   $(idstr).val(id);
    var scorestr="#score_"+num;
    $(scorestr).html(score);
    var numstr="#num_"+num;
    $(numstr).val(1);
     var allstr="#all_"+num;
     score=parseFloat(score).toFixed(2);
    $(allstr).html(score);
    total();
      $('#pro').window('close');
 }});


function empsearch(){
var empsearchvalue=$("#empsearchvalue").val();

 var site_url=$("#site_url").val();
  var url=encodeURI(site_url+"index.php/entering/get_emp_search/?key="+empsearchvalue);
   //var url=site_url+"index.php/entering/get_emp_search/?key="+empsearchvalue;

 $('#emp_tt').datagrid('options').url=url;    
  $('#emp_tt').datagrid('reload');
}

function prosearch(){
var prosearchvalue=$("#prosearchvalue").val();
var site_url=$("#site_url").val();
  var url=encodeURI(site_url+"index.php/entering/get_pro_search/?key="+prosearchvalue);
 $('#pro_tt').datagrid('options').url=url;    
  $('#pro_tt').datagrid('reload');
}

  function total(){
      var rownum=parseInt($("#rownum").val());
       var i=1;
      
       var total=0;
       for (i=1;i<=rownum;i++) {
        var idstr="#id_"+i;
           var scorestr="#score_"+i;
          var numstr="#num_"+i;
          var id=$(idstr).html();
          var score=$(scorestr).html();
         var num=$(numstr).val();
    
           if(typeof(num) !="undefined" && num !=""){
            var tmp=parseFloat(score)*parseFloat(num);
           // alert(score+"|"+num);
               total=total+tmp;
             }
          
       }  
     // alert(total);
     total=total.toFixed(2);
       $("#total").html(total);
        }



        $(function () {
      $('.app').footable().on('click', '.row-delete', function(e) {
                      e.preventDefault();
                      var footable = $('.app').data('footable');
                      var row = $(this).parents('tr:first');
                      footable.removeRow(row);
                      total();
      });

            $('.add-row').click(function(e) {
                e.preventDefault();
                //get the footable object
                var footable = $('.app').data('footable');
                var rownum=parseInt($("#rownum").val())+1;
                $("#rownum").val(rownum);
                //build up the row we are wanting to add
                var newRow = '<tr><td><span id="id_'+rownum+'">'+rownum+'</td><td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#add" class=" add-row">+</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="row-delete" href="#">-</span></a></td><td><a href="#"><input type="text" size="10" id="proname_'+rownum+'" onclick="add('+rownum+')" value=""><input type="hidden" value="0" id="proid_'+rownum+'"></a></td><td><span id="score_'+rownum+'"></span></td><td ><input type="text" size="5" id="num_'+rownum+'" onblur="change('+rownum+')"></td><td ><span id="all_'+rownum+'" style="font-size: 18px;font-weight: bold"></span></td></tr>';
                footable.appendRow(newRow);
            });
        });


        function add(row){
             $("#rowcount").val(row);
                 pro(row);
        }


        function change(row){
          
          var scorestr="#score_"+row;
           var score=$(scorestr).html();
         
           var numstr="#num_"+row;
          var num=$(numstr).val();
       
          var all=parseFloat(score)*parseFloat(num);
          
          var allstr="#all_"+row;
          $(allstr).html(all.toFixed(2));
         total();
        }


      

       function save(){
       var rownum=parseInt($("#rownum").val());
       var i=1;
       var str="";
       var site_url=$("#site_url").val();
       var empid=$("#empid").val();
       var time=$("#time").val();
       var total=$("#total").html();
       for (i=1;i<=rownum;i++) {
       
          var idstr="#id_"+i;
          var pronamestr="#proname_"+i;
          var proidstr="#proid_"+i;
          var scorestr="#score_"+i;
          var numstr="#num_"+i;
          var allstr="#all_"+i;
         var id=$(idstr).html();
         var proname=$(pronamestr).val();
         var proid=$(proidstr).val();
         var score=$(scorestr).html();
         var num=$(numstr).val();
         var all=$(allstr).html();
         
           if( proid!="0" && typeof(proid) !="undefined" ){
             str=str+"*"+id+"-"+proname+"-"+proid+"-"+score+"-"+num+"-"+all;
             }
       }
       //alert(str);

       $.ajax({
          type:"post",
          dataType:"text",
          url:site_url+"index.php/entering/save/",
          data:{'result':str,'empid':empid,'time':time,'total':total},
          success:function(msg){
              if("success"==msg){window.location.reload();}else{alert("保存失败！");}
          } 
          });
      
       }
    </script>
<script>
      $("body").keydown(function() {
        if (event.keyCode == "13") {//keyCode=13是回车键
            empsearch();
            prosearch();
        }
         });   
</script>

</body>
</html>

<?php }elseif ($action=="edit") {?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title></title>

  
  <script type="text/javascript" src="<?php echo site_url(); ?>app/views/assetstwo/easyui/jquery.min.js"></script>
 

  <link href="<?php echo site_url(); ?>app/views/assetstwo/table/footable.core.css?v=2-0-1" rel="stylesheet" type="text/css"/>
    <link href="<?php echo site_url(); ?>app/views/assetstwo/table/footable-demos.css" rel="stylesheet" type="text/css"/>
   
    <script>
        if (!window.jQuery) { document.write('<script src="js/jquery-1.9.1.min.js"><\/script>'); }
    </script>
    <script src="<?php echo site_url(); ?>app/views/assetstwo/table/footable.js?v=2-0-1" type="text/javascript"></script>
    <script src="<?php echo site_url(); ?>app/views/assetstwo/table/footable.sort.js?v=2-0-1" type="text/javascript"></script>
    <script src="<?php echo site_url(); ?>app/views/assetstwo/table/footable.filter.js?v=2-0-1" type="text/javascript"></script>
    <script src="<?php echo site_url(); ?>app/views/assetstwo/table/footable.paginate.js?v=2-0-1" type="text/javascript"></script>
  
    <script src="<?php echo site_url(); ?>app/views/assetstwo/table/demos.js" type="text/javascript"></script>
    <!-- paste this code into your webpage -->
<link href="<?php echo site_url(); ?>app/views/assetstwo/table/tablecloth.css" rel="stylesheet" type="text/css" media="screen" /> 
<script type="text/javascript" src="<?php echo site_url(); ?>app/views/assetstwo/table/tablecloth.js"></script>
<!-- end -->

<link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/assetstwo/easyui/themes/bootstrap/easyui.css">
  <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/assetstwo/easyui/themes/icon.css">
  <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/assetstwo/easyui/demo.css">
   <script type="text/javascript" src="<?php echo site_url(); ?>app/views/assetstwo/easyui/jquery.easyui.min.js"></script>
   <script>
 $(function(){
      $('#cc').layout();
      setHeight();
    });
    
   
    function setHeight(){
      var c = $('#cc');
      var p = c.layout('panel','center'); // get the center panel
      var oldHeight = p.panel('panel').outerHeight();
      p.panel('resize', {height:'500'});
      var newHeight = p.panel('panel').outerHeight();
      c.layout('resize',{
        height: (c.height() + newHeight - oldHeight)
      });
    }


  function emp(){
   
    $('#emp').window('open');
  }


  function pro(){
   
    $('#pro').window('open');
  }


 
</script>
</head>
<body>



<div id="cc" style="width:100%;height:500px;">
    <div data-options="region:'north'" style="height:80px">
    <div style="height:15px;"></div>
     <div class="table">
     <table><tr><td>员工姓名:</td><td><input type="text" value="<?php echo $order->empname;?>" size="1" onclick="emp()" id="empname"><input type="hidden" value="<?php echo $order->empid; ?>" id="empid"></td><td>所属部门:</td><td><span id="empdepart"><?php echo $order->empdepartname;?></span></td><td>联系电话:</td><td><span id="empmobile"><?php echo $order->emptelphone;?></span></td><td>时间:</td><td><input type="text" id="time" disabled="disabled" value="<?php echo @date("Y-m-d H:i:s",$order->time);?>" size="1"></td></tr></table> 

</div>
    </div>
    <div data-options="region:'south'" style="height:80px;">
        <div style="height:10px;"></div>
         <div class="row">
              <div class="form-actions " style="width:30%;height:100%;position: relative;left:40%">

                <button type="button" class="button button-primary" onclick="saveedit()">保存单据</button>
                <button type="reset" class="button">重置</button>
              </div>
            </div>

    </div>




  <div id="emp" class="easyui-window" title="选择员工" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:800px;height:400px;padding:5px;top:10px;left:200px;">
 
<div class="" style="width:600px;height: 350px;float:right;border: solid 1px #CCC">
  <div class="" style="width: 100%;height: 35px;border:solid 0px #CCC">
  <div style="width: 19%;height: 29px;border: solid 0px #ccc;float:right;text-align: center"><button style="width: 100%;height: 110%" onclick="empsearch()">搜索</button></div>
    <div style="width: 80%;height: 29px;border: solid 0px #ccc;float:left"><input type="text" style="width: 100%;height: 90%;" id="empsearchvalue"></div>
    
  </div>
   <table id="emp_tt" class="easyui-datagrid" title="员工列表" style=""
            data-options="singleSelect:true,url:'<?php  echo site_url();?>index.php/entering/get_emp',method:'get'">
        <thead>
            <tr>
                <th data-options="field:'id'" width="40">编码</th>
                <th data-options="field:'name'" width="100">员工名称</th>
                <th data-options="field:'address'" width="150">地址</th>
                <th data-options="field:'mobile'" width="100">联系电话</th>
                <th data-options="field:'code'" width="100">编号</th>
                 <th data-options="field:'depart'" width="100"></th>
            </tr>
        </thead>
    </table>
</div>
<div class="" style="width:165px;height: 350px;float:left;border: solid 1px #CCC">
  
<ul class="easyui-tree" id="empcategory" data-options="url:'<?php  echo site_url();?>index.php/entering/get_emp_category',method:'get',animate:true"></ul>
</div>
  </div>



   <div id="pro" class="easyui-window" title="选择积分项" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:800px;height:400px;padding:5px;top:10px;left:200px;">
       <div class="" style="width:600px;height: 350px;float:right;border: solid 1px #CCC">
  <div class="" style="width: 100%;height: 35px;border:solid 0px #CCC">
  <div style="width: 19%;height: 29px;border: solid 0px #ccc;float:right;text-align: center"><button style="width: 100%;height: 110%" onclick="prosearch()">搜索</button></div>
    <div style="width: 80%;height: 29px;border: solid 0px #ccc;float:left"><input type="text" id="prosearchvalue" style="width: 100%;height: 90%;"></div>
    
  </div>
   <table id="pro_tt" class="easyui-datagrid" title="积分项列表" style=""
            data-options="singleSelect:true,url:'<?php  echo site_url();?>index.php/entering/get_pro',method:'get'">
        <thead>
            <tr>
                <th data-options="field:'id'" width="40">编码</th>
                <th data-options="field:'name'" width="100">积分项名称</th>
                <th data-options="field:'change_num'" width="150">置换分数</th>
                <th data-options="field:'sale'" width="100">专业非专业</th>
               
            </tr>
        </thead>
    </table>
</div>
<div class="" style="width:165px;height: 350px;float:left;border: solid 1px #CCC">
  
<ul class="easyui-tree" id="procategory" data-options="url:'<?php  echo site_url();?>index.php/entering/get_pro_category',method:'get',animate:true"></ul>
</div>

   

    
  </div>



    <div data-options="region:'center'" style="padding:10px;height:500px">

<!--数据表格开始-->
    <div class="table">
               <input type="hidden" value="<?php echo count($products); ?>" id="rownum">
               <input type="hidden" value="<?php echo count($products); ?>" id="rowcount">
               <input type="hidden" value="<?php echo $order->id; ?>" id="order_id">
        <table class="app" data-filter="#filter" data-page-size="100">
          <thead>
            <tr>
               <th >操作</th>
              <th data-toggle="true">
                编号
              </th>
              <th data-hide="phone">
                积分项目名称
              </th>
              <th data-hide="phone">
                积分项目对应积分
              </th>
              <th data-hide="phone">
                  对应数量
              </th>
              <th data-hide="phone">
                小计
              </th>
              
            </tr>
          </thead>
          <tbody>
          <?php if(empty($products)){

            }else{ $i=1;?>
          <?php foreach ($products as $key => $value) {?>
            <tr>
                <td><span id="id_<?php echo $i;?>"><?php echo $i;?></span></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#add" class=" add-row">+</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="row-delete" href="#">-</span></a></td>
              <td><a href="#"><input type="text" size="10" onclick="add(<?php echo $i;?>)" id="proname_<?php echo $i;?>" value="<?php echo $value['product_name']; ?>"></a><input type="hidden" value="<?php echo $value['product_id']; ?>" id="proid_<?php echo $i;?>"></td>
              <td><span id="score_<?php echo $i;?>"><?php echo $value['score'];?></span></td>
              <td ><input type="text" size="5" onblur="change(<?php echo $i;?>)" id="num_<?php echo $i;?>" value="<?php echo $value['product_num'];?>"></td>
              <td ><span id="all_<?php echo $i;?>" style="font-size: 18px;font-weight: bold"><?php echo $value['total'];?></span></td>
            </tr>
         <?php  $i++;}} ?>
           
           
          </tbody>
                    <tfoot >
                    <tr>
                        <td colspan="4"></td><td><h2>总计:</h2></td><td><span id="total" style="font-size: 25px;font-weight: bold"><?php echo $order->sumtotal; ?></span></td>
                    </tr>
                    </tfoot>
        </table>


        </div>
       
<!--数据表格结束-->

<input type="hidden" value="<?php echo site_url(); ?>" id="site_url">

  </div>



  <script type="text/javascript">


$('#empcategory').tree({
  onClick:function(row){
  var row = $('#empcategory').tree('getSelected');
  var id=row.id;
   var site_url=$("#site_url").val();
  var url=site_url+"index.php/entering/get_emp/?id="+id;
    $('#emp_tt').datagrid('options').url=url;  
  $('#emp_tt').datagrid('reload');
}});

$('#procategory').tree({
  onClick:function(row){
  var row = $('#procategory').tree('getSelected');
  var id=row.id;
     var site_url=$("#site_url").val();
  var url=site_url+"index.php/entering/get_pro/?id="+id;
    $('#pro_tt').datagrid('options').url=url;  
  $('#pro_tt').datagrid('reload');
}});

$('#emp_tt').datagrid({
 onClickRow:function(row){
    var row=$("#emp_tt").datagrid('getSelected');
    var id=row.id;
    var name=row.name;
    var code=row.code;
    var depart=row.depart;
    /* var address=row.address;*/
     var mobile=row.mobile;
     $("#empid").val(id);
     $("#empname").val(name);
     $("#empmobile").html(mobile);
    /* $("#empaddress").html(address);*/
     $("#empdepart").html(depart);
      $('#emp').window('close');
 }});


$('#pro_tt').datagrid({
 onClickRow:function(row){
    var row=$("#pro_tt").datagrid('getSelected');
    var id=row.id;
    var name=row.name;
    var score=row.change_num;
   var num=$("#rowcount").val();
   var namestr="#proname_"+num;
   $(namestr).val(name);
      var idstr="#proid_"+num;
   $(idstr).val(id);
    var scorestr="#score_"+num;
    $(scorestr).html(score);
    var numstr="#num_"+num;
    $(numstr).val(1);
     var allstr="#all_"+num;
     score=parseFloat(score).toFixed(2);
    $(allstr).html(score);
    total();
      $('#pro').window('close');
 }});


function empsearch(){
var empsearchvalue=$("#empsearchvalue").val();
alert(empsearchvalue);
 var site_url=$("#site_url").val();
  var url=encodeURI(site_url+"index.php/entering/get_emp_search/?key="+empsearchvalue);
  //var url=site_url+"index.php/entering/get_emp_search/?key="+empsearchvalue;
 $('#emp_tt').datagrid('options').url=url;    
  $('#emp_tt').datagrid('reload');
}

function prosearch(){
var prosearchvalue=$("#prosearchvalue").val();
var site_url=$("#site_url").val();
  var url=encodeURI(site_url+"index.php/entering/get_pro_search/?key="+prosearchvalue);
 $('#pro_tt').datagrid('options').url=url;    
  $('#pro_tt').datagrid('reload');
}

  function total(){
      var rownum=parseInt($("#rownum").val());
       var i=1;
      
       var total=0;
       for (i=1;i<=rownum;i++) {
        var idstr="#id_"+i;
           var scorestr="#score_"+i;
          var numstr="#num_"+i;
          var id=$(idstr).html();
          var score=$(scorestr).html();
         var num=$(numstr).val();
    
           if(typeof(num) !="undefined" && num !=""){
            var tmp=parseFloat(score)*parseFloat(num);
           // alert(score+"|"+num);
               total=total+tmp;
             }
          
       }  
     // alert(total);
     total=total.toFixed(2);
       $("#total").html(total);
        }



        $(function () {
      $('.app').footable().on('click', '.row-delete', function(e) {
                      e.preventDefault();
                      var footable = $('.app').data('footable');
                      var row = $(this).parents('tr:first');
                      footable.removeRow(row);
                      total();
      });

            $('.add-row').click(function(e) {
                e.preventDefault();
                //get the footable object
                var footable = $('.app').data('footable');
                var rownum=parseInt($("#rownum").val())+1;
                $("#rownum").val(rownum);
                //build up the row we are wanting to add
                var newRow = '<tr><td><span id="id_'+rownum+'">'+rownum+'</td><td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#add" class=" add-row">+</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="row-delete" href="#">-</span></a></td><td><a href="#"><input type="text" size="10" id="proname_'+rownum+'" onclick="add('+rownum+')" value=""><input type="hidden" value="0" id="proid_'+rownum+'"></a></td><td><span id="score_'+rownum+'"></span></td><td ><input type="text" size="5" id="num_'+rownum+'" onblur="change('+rownum+')"></td><td ><span id="all_'+rownum+'" style="font-size: 18px;font-weight: bold"></span></td></tr>';
                footable.appendRow(newRow);
            });
        });


        function add(row){
             $("#rowcount").val(row);
                 pro(row);
        }


        function change(row){
          
          var scorestr="#score_"+row;
           var score=$(scorestr).html();
         
           var numstr="#num_"+row;
          var num=$(numstr).val();
       
          var all=parseFloat(score)*parseFloat(num);
          
          var allstr="#all_"+row;
          $(allstr).html(all.toFixed(2));
         total();
        }


      

       function saveedit(){
       var rownum=parseInt($("#rownum").val());
       var i=1;
       var str="";
       var site_url=$("#site_url").val();
       var empid=$("#empid").val();
       var time=$("#time").val();
       var total=$("#total").html();
       var order_id=$("#order_id").val();
       for (i=1;i<=rownum;i++) {
          
          var idstr="#id_"+i;
          var pronamestr="#proname_"+i;
          var proidstr="#proid_"+i;
          var scorestr="#score_"+i;
          var numstr="#num_"+i;
          var allstr="#all_"+i;
         var id=$(idstr).html();
         var proname=$(pronamestr).val();
         var proid=$(proidstr).val();
         var score=$(scorestr).html();
         var num=$(numstr).val();
         var all=$(allstr).html();

           if( proid!="0" && typeof(proid) !="undefined" ){
             str=str+"*"+id+"-"+proname+"-"+proid+"-"+score+"-"+num+"-"+all;
             }
       }
       //alert(str+empid+time);

       $.ajax({
          type:"post",
          dataType:"text",
          url:site_url+"index.php/entering/editsave/",
          data:{'result':str,'empid':empid,'time':time,'total':total,'order_id':order_id},
          success:function(msg){
              if("success"==msg){window.location.reload();}else{alert("保存失败！");}
          } 
          });
      
       }
    </script>
<script>
      $("body").keydown(function() {
        if (event.keyCode == "13") {//keyCode=13是回车键
            empsearch();
            prosearch();
        }
         });   
</script>

</body>
</html>
<?php } ?>
